home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / SAT 2.1.2 / SAT Invaders sample ƒ / main.p < prev    next >
Encoding:
Text File  |  1994-06-10  |  9.9 KB  |  118 lines  |  [TEXT/PJMM]

  1. uest, has. No high scores or even score, only}
  2. { one life, doesn't save settings, only one kind of enemy, no special effects like explosions}
  3. { etc. However, it is still a full Mac application with menus and event handling (using}
  4. {TransSkel). There are now some even more "minimal" demos without that.}
  5.  
  6. program SATInvaders;
  7.  
  8.     uses
  9.         TransSkel, SAT, GameGlobals, SoundConst, sPlayer, sEnemy, sShot, sMissile;
  10.  
  11.     var
  12.         soundFlag, plotFastFlag: Boolean;
  13.  
  14. { -------------------------------------------------------------------- }
  15. {                                Game driver procedures                                }
  16. { -------------------------------------------------------------------- }
  17.  
  18. { Setup a new level. This is called when the game starts and at each new level.}
  19.     procedure SetupLevel (level: integer);
  20.         var
  21.             i, j: integer;
  22.             sp: SpritePtr;
  23.     begin { SetupLevel }
  24.  
  25. { Clear the Sprite list! Note that this leaves the images "dead" on the screen,}
  26. { but we will soon erase them. }
  27.         while gSAT.sRoot <> nil do
  28.             KillSprite(gSAT.sRoot);
  29.  
  30.         missileCount := 0; { count variable in mMissile }
  31.  
  32. { Create all the enemy sprites for the level, depending on the level number. }
  33.         for i := 0 to (level + 1) do
  34.             for j := 0 to (level div 2) + 1 do
  35.                 sp := NewSprite(-3, i * 40 + 2, j * 40 - 40 * (level div 2 + 1), @SetupEnemy);
  36.  
  37. { Make the player sprite. }
  38.         sp := NewSprite(2, gSAT.offSizeH div 2, gSAT.offSizeV - 40, @SetupPlayer);
  39.  
  40. { Copy BackScreen to OffScreen to erase old sprites. }
  41.         CopyBits(gSAT.backScreen^.portbits, gSAT.offScreen^.portbits, gSAT.offScreen^.portrect, gSAT.offScreen^.portrect, srcCopy, nil);
  42.         PeekOffScreen;
  43.     end; { SetupLevel }
  44.  
  45. { Start a new game. Initialize level, score, number of lives, and call setuplevel to make the first level. }
  46.     procedure StartGame;
  47.     begin
  48.         Level := 1;
  49.         SetupLevel(level);
  50.     end;
  51.  
  52. { Declare forward since we want to call it from MoveIt }
  53.     procedure DoFileMenu (item: integer);
  54.     forward;
  55.  
  56. { This routine is the game driver. It calls RunSAT repeatedly until the game ends or is paused. }
  57. { I also read the keyboard here. This could optionally be moved to the "player object" module. }
  58.  
  59.     procedure MoveIt;
  60.         var
  61.             t: longint;
  62.             theEvent: EventRecord; { för att testa musklick }
  63.     begin
  64.         stillrunning := true; { A flag that tells whether or not to quit this routine. }
  65.  
  66. { Hide cursor and menu bar }
  67.  { NOTE: No matter how we leave the MoveIt procedure, we should ShowCursor. }
  68.         HideCursor;
  69.         HideMBar(gSAT.wind);
  70.         PeekOffscreen; {We must redraw the menu bar area. I'm lazy and redraw it all.}
  71.  
  72. { Main loop! Keep running until the game is paused or ends. }
  73.         while stillrunning = true do
  74.             begin
  75.                 t := TickCount; {Remember when we started the last turn through the loop.}
  76.  
  77. { Here is the real heart of the loop: call Animator once per loop. It will call all the objects,}
  78. { draw and erase them, sort them etc. }
  79.                 RunSAT(plotFastFlag);
  80.  
  81. { All the rest of the main loop is game specific, next level, bonus handling, etc. }
  82.  
  83. {Handle the speed of the invaders. Since all move the same way, this is done globally.}
  84.                 if globalspeed.h = 0 then
  85.                     begin
  86.                         downcount := pred(downcount);
  87.                         if downcount <= 0 then
  88.                             begin
  89.                                 globalspeed.h := -lasth;
  90.                                 globalspeed.v := 0;
  91.                                 turnflag := false;
  92.                             end;
  93.                     end
  94.                 else if turnflag then
  95.                     begin
  96.                         downcount := 10;
  97.                         lasth := globalspeed.h;
  98.                         globalspeed.h := 0;
  99.                         globalspeed.v := 3;
  100.                     end;
  101.  
  102. {End of level? If so, set up a new one!}
  103.                 if not gSAT.anyMonsters then
  104.                     begin
  105.                         SATSoundShutUp;
  106.                         level := level + 1;
  107.                         SetupLevel(level);
  108.                     end; {if not anymonsters}
  109.  
  110. { Check for keys being pressed - but don't allow background processing.}
  111. { If you want background processing, either use GetNextEvent+SystemTask or WaitNextEvent (the modern call).}
  112.                 if GetOSEvent(keyDownMask, theEvent) then { keydown only }
  113.                     if BitAnd(theEvent.modifiers, cmdKey) <> 0 then {Command key pressed?}
  114.                         case char(BitAnd(theEvent.message, charCodeMask)) of {With what key?}
  115.                             'q': 
  116.                                 begin {Quit!}
  117.                                     SkelWhoa;        {Tell TransSkel to quit.}
  118. { Do all the things